package com.czy.mapper;

import com.czy.pojo.Emp;
import com.czy.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * 员工信息
 */
@Mapper
public interface EmpMapper {

    //-------------------------------原始分页查询实现-------------------------------
    //查询测试
//    @Select("select id, username, password, name, gender, phone, " +
//            "job, salary, image, entry_date, dept_id, create_time, update_time from emp")
//    public List<Emp> findAll();
//
//    //查询总记录数
//    @Select("select count(*) from emp left join dept on emp.dept_id = dept.id")
//    public Long count();
//
//    //查询结果列表
//    @Select("select e.id, e.username, e.password, e.name, e.gender, e.phone, e.job, e.salary, e.image, e.entry_date, e.dept_id, e.create_time, e.update_time , d.name deptName from emp e left join dept d on e.dept_id = d.id " +
//            "order by e.update_time desc limit #{start},#{pageSize} ")
//    public List<Emp> list(Integer start, Integer pageSize);

//    @Select("select e.id, e.username, e.password, e.name, e.gender, e.phone, e.job, e.salary, e.image, e.entry_date, e.dept_id, e.create_time, e.update_time , d.name deptName from emp e left join dept d on e.dept_id = d.id " +
//            "order by e.update_time desc")
    /*public List<Emp> list(String name, Integer gender, LocalDate begin, LocalDate end);*/

    /**
     * 条件查询员工信息
     */
    public List<Emp> list(EmpQueryParam empQueryParam);

    /**
     * 新增员工基本信息
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")//获取到生成的主键 -- 主键返回
    @Insert("insert into emp(username,name,gender,phone,job,salary,image,entry_date,dept_id,create_time,update_time)" +
            "values(#{username},#{name},#{gender},#{phone},#{job}," +
            "#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    public void insert(Emp emp);

    /**
     * 根据ID批量删除员工基本信息
     */
    public void deleteByIds(List<Integer> ids);

    /**
     * 根据ID查询员工信息以及工作经历信息
     */
    public Emp getById(Integer id);

    public void updateEmp(Emp emp);

    /**
     *  统计员工职位人数
     */
    @MapKey("pos")
    public List<Map<String,Object>> countEmpJobData();

    /**
     * 统计员工性别人数
     */
    @MapKey("name")
    public List<Map<String, Object>> countEmpGenderData();

    /**
     * 查询全部员工的信息
     */
    @Select("select ID, USERNAME, PASSWORD, NAME, GENDER, PHONE, JOB, SALARY, IMAGE, ENTRY_DATE, DEPT_ID, CREATE_TIME, UPDATE_TIME from emp")
    public List<Emp> findAll();

    /**
     * 根据部门ID查询对应的员工数
     */
    @Select("select count(dept_id) from emp group by dept_id HAVING dept_id = #{id}")
    public Integer getCount(Integer id);

    /**
     * 根据用户名和密码查询员工信息
     */
    @Select("select id,username,name  from emp " +
            "where username = #{username} and password = #{password}")
    public Emp selectByUsernameAndPassword(Emp emp);
}
